package com.example.testproject;

import java.net.URLEncoder;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.support.v4.widget.SimpleCursorAdapter.ViewBinder;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Screen5 extends Activity implements View.OnClickListener {
	EditText uname;
	EditText pwd;
	Button loginbtn;
	String user_name;
	String user_pwd;
	String name, email, phone;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.screen5);
        uname = (EditText)findViewById(R.id.email_id);
        pwd = (EditText)findViewById(R.id.password);
        loginbtn = (Button)findViewById(R.id.login1);
        
  
        
		
		
		Button puneTab01 = (Button) findViewById(R.id.puneTab01);
		Button puneTab02 = (Button) findViewById(R.id.puneTab02);
		Button puneTab03 = (Button) findViewById(R.id.puneTab03);
		Button puneTab04 = (Button) findViewById(R.id.puneTab04);
		puneTab01.setOnClickListener(this);
		puneTab02.setOnClickListener(this);
		puneTab03.setOnClickListener(this);
		puneTab04.setOnClickListener(this);
		
		loginbtn.setOnClickListener(this);
		
		
    }
    	 
		
		
		     //change this boo_now to profile  
 
                	 public void onClick(View v) {
                	        switch (v.getId()) {
                	        case R.id.login1:
                	        	user_name = uname.getText().toString();
                	            user_pwd = pwd.getText().toString();
                	            
                	            //Using HttpGet
                	             
                	            try
                	            {
                		            HttpClient client = new DefaultHttpClient();  
                		            user_name = URLEncoder.encode(user_name, "utf-8");
                		            user_pwd = URLEncoder.encode(user_pwd, "utf-8");
                			        String getURL = "http://10.0.2.2/cubito/login.php"+"?uname="+user_name+"&pwd="+user_pwd;
                			        HttpGet get = new HttpGet(getURL);
                			        HttpResponse responseGet = client.execute(get);  
                			        HttpEntity resEntityGet = responseGet.getEntity();
                			        String getURL2 = "http://10.0.2.2/cubito/email.php"+"?uname="+user_name+"&pwd="+user_pwd;
                			        HttpGet get2 = new HttpGet(getURL2);
                			        HttpResponse responseGet2 = client.execute(get2);  
                			        HttpEntity resEntityGet2 = responseGet2.getEntity();  
                			        String getURL3 = "http://10.0.2.2/cubito/phone.php"+"?uname="+user_name+"&pwd="+user_pwd;
                			        HttpGet get3 = new HttpGet(getURL3);
                			        HttpResponse responseGet3 = client.execute(get3);  
                			        HttpEntity resEntityGet3 = responseGet3.getEntity();  
                			        
                			        if (resEntityGet != null) 
                			        {  
                			        	//Toast.makeText(getApplicationContext(), "in my if", Toast.LENGTH_LONG).show();
                			                    //do something with the response
                	                    		name = EntityUtils.toString(resEntityGet);
                	                    		email = EntityUtils.toString(resEntityGet2);
                	                    		phone = EntityUtils.toString(resEntityGet3);
                			                   // Log.d("response", response);
                	                    		Intent intent = new Intent(/*FirstActivity.this*/ v.getContext(), Screen6.class);
                	             			   intent.putExtra("name", name);
                	             			   intent.putExtra("email", email);
                	             			   intent.putExtra("phone", phone);
                	             			   startActivity(intent);
                			        }
                			        if(name.compareTo(null)==1)
                			        {
                			        	Toast.makeText(getApplicationContext(), "Login Successful!", Toast.LENGTH_LONG).show();
                			        	//Intent intent_next = new Intent(main.this,json_parse2.class);
                			           // startActivity(intent_next);
                			            
                			        
                			            
                			        }
                			        else
                			        	Toast.makeText(getApplicationContext(), "Invalid User ID or Password", Toast.LENGTH_LONG).show();

                		            } 
                	            catch(Exception e)
                	            {}

                	            break;
                	                        	        case R.id.puneTab01:
                	        	Intent intent2 = new Intent(/*FirstActivity.this*/ v.getContext(), Screen1.class);
                			    startActivity(intent2);

                	            break;
                	        case R.id.puneTab02:
                	        	Intent intent3 = new Intent(/*FirstActivity.this*/ v.getContext(), Screen8.class);
                			    startActivity(intent3);

                	            break;
                	        case R.id.puneTab03:
                	        	Intent intent4 = new Intent(/*FirstActivity.this*/ v.getContext(), Screen10.class);
                			    startActivity(intent4);

                	            break;
                	        case R.id.puneTab04:
                	        	Intent intent5 = new Intent(/*FirstActivity.this*/ v.getContext(), Screen9.class);
                			    startActivity(intent5);

                	            break;


                	        default:
                	            break;
                	        }
                 }
		
    
   
}

